from interface.frame.apis.admin.admin_api import AdminApi


class GoodsCategory(AdminApi):

    def add(self, data):
        """
        添加商品类目的接口实现
        :param data:
        :return:
        """
        # 定义添加商品类目URL
        add_url = "admin/category/create"
        # 组装请求体
        req = {
            "method": "post",
            "url": add_url,
            "json": data
        }
        # 发起添加商品类目请求
        add_r = self.send_api(req)
        return add_r.json()

    def delete(self, goods_id):
        """
        删除商品类目的接口实现
        :param goods_id:
        :return:
        """
        # 定义删除商品类目URL
        del_url = "admin/category/delete"
        # 组包json数据
        del_data = {
            "id": goods_id,
            "name": "张三",
            "level": "L2"
        }
        # 组包请求体
        req = {
            "method": "post",
            "url": del_url,
            "json": del_data
        }
        # 发起请求
        del_r = self.send_api(req)
        return del_r.json()

    def list(self):
        """
        获取商品类目列表的接口实现
        :return:
        """
        # 定义商品类目列表的URL
        list_url = "admin/category/list"
        # 组包请求体
        req = {
            "method": "GET",
            "url": list_url,
        }
        # 发起请求
        list_r = self.send_api(req)
        return list_r.json()
